const cookieObj = myGetCookie();
let name = cookieObj.name;
$('[name = "name"]').val(cookieObj.name);

$('.wrap').click(function(e){
    if(e.target.getAttribute('name')=='false'){
        window.location.href = './index.html';
    }else if(e.target.getAttribute('name')=='true'){
      let oldpwd = $('[name = "pwd"]').val();
      let newpwd = $('[name = "newpwd"]').val();
      let renewpwd = $('[name = "renewpwd"]').val();
      if(newpwd != renewpwd){
         $('[name = "p1"]').html('密码和确认密码不一致！');
      }else if(newpwd ==oldpwd){
         $('[name = "p1"]').html('新旧密码一致！');
      }else{
        $('[name = "p1"]').html('');
        console.log(name,newpwd);
        //传参
        const xhr = myPromiseJQueryAjax( '../server/repassword.php' , 'post' , {name:name,newpwd:newpwd,oldpwd:oldpwd} , 'json' );
        xhr.then(function(res){
            console.log(res);
        if( res === false ){
            window.alert('修改失败！');
        }else if( res == true ){
            console.log(res);
            window.alert('修改成功！');
            //跳转登录界面
            window.location.href = './login.html';
        }
        })
      }
    }
})
